import './boots';
import router from './routers/app.routers';
import store from './store/index';
import App from './App.vue';
import {sync} from 'vuex-router-sync';
import {install} from 'build';
import Clipboard from 'clipboard';

import './mock';

install(Vue);

Object.defineProperty(Vue.prototype, 'consts', {value: consts});
Object.defineProperty(Vue.prototype, '_result', {value: _.result});

sync(store, router);

Vue.config.productionTip = false;

new Clipboard('.clipboard-btn');


router.beforeEach((to, from, next) => {
  if (to.meta.needPermission) {
    if (store.getters.isLogin) {
      next();
    } else {
      next({
        // name: 'login'
        name: 'home-page'
      });
    }
  } else {
    next();
  }
});

store.dispatch(types.CHECK_IS_SIGNIN)
  .finally(() => {
    new Vue({
      el: '#app',
      render: h => h(App),
      store,
      router,
    });
  });
